<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <title>收益支付</title>
    <!--    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
        <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <script src="../lib/layuimini/lib/layui-v2.5.5/layui.js"></script>
        <script src="../lib/layuimini/js/lay-config.js"></script>-->
    <script src="layui/layui.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css"/>

    <script type="text/javascript">
        var layid =11;
        layui.use(['element', 'form', 'table', 'layer', 'laydate'], function () {
            var layer = layui.layer;
            var $ = layui.$;
            var table = layui.table;
            var form = layui.form;
            var formSelects = layui.formSelects;
            var laydate = layui.laydate;
            var fundId=$("#fundId").val();
            //执行一个laydate实例
            laydate.render({
                elem: '#statDate' //指定元素
            });

            table.render({
                elem: '#userTable',
                url:'cashInventSelect',
                page: true,
                height:'full-50',
                cellMinWidth: 50,
                cols:[
                    [
                        {type: 'checkbox', fixed: 'left'}
                        ,{field: 'bankName', title: '银行名称', align:'center'}
                        , {field: 'accounName', title: '账户名称', align:'center'}
                        , {field: 'balance', title: '余额', align:'center'}
                        , {field: 'cashType', title: '存款类型', align:'center',templet:function (tm) {
                            if (tm.cashType==1){
                                return "活期"
                            }else {
                                return "定期"
                            }
                        }}
                        , {field: 'accounRate', title: '卡号利率', align:'center'}
                        , {field: 'cashInventorysTime', title: '业务日期'}
                        , {field: 'day', title: '计息期限', align:'center',templet:function (tom) {
                            if (tom.day==1){
                                return "360"
                            } else if (tom.day==2) {
                                return "365"
                            }else {
                                return "366"
                            }
                        }}
                        , {field: 'interest', title: '利息(元)', align:'center'}
                    ]
                ]
            });
            //债券利息
            table.render({
                elem:'#userTable2' ,
                url: 'bondSecurity',
                page: true,
                height:'full-50',
                cellMinWidth: 50,
                cols:[
                    [
                        {type: 'checkbox', fixed: 'left'}
                        ,{field: 'bondName', title: '债券名称', align:'center'}
                        ,{field: 'bondId', title: '债券代码', align:'center'}
                        ,{field: 'bondRate', title: '票面利率%', align:'center'}
                        ,{field: 'securityNum', title: '债券数量', align:'center'}
                        ,{field: 'bondType', title: '债券类型',align:'center',templet:function (son) {
                            if (son.bondType==1){
                                return "银行间"
                            } else {
                                return "非银行间"
                            }
                        }}
                        ,{field: 'bondMoney', title: '票面金额',  align:'center'}
                        ,{field: 'securityInventorsTime', title: '业务日期',  align:'center'}
                        ,{field: 'bondstartDate', title: '计息起始日',  align:'center'}
                        , {field: 'interest', title: '利息(元)', align: 'center'}
                    ]
                ]
            });
            table.render({
                elem: '#userTable3',
                url: 'fundTwoFees',
                page: true,
                height: 'full-20',
                minLength:80,
                cols: [
                    [ //表头
                        {type: 'checkbox', fixed: 'left'}
                        // ,{field: 'fundName', title: '基金名称',align:'center'}
                        ,{field: 'fundId', title: '基金编号', align:'center'}
                        ,{field: 'custodianCost', title: '管理人费率(%)',  align:'center'}
                        ,{field: 'bankCost', title: '托管人费率(%)',  align:'center'}
                        ,{field: 'capital', title: '资产净值',  align:'center'}
                        // ,{field: 'valueStatisticsDate', title: '业务日期',  align:'center'}
                        ,{field: 'custodianInterest', title: '管理费利息(元)',  align:'center'}
                        ,{field: 'bankInterest', title: '托管费利息(元)',  align:'center'}
                    ]
                ]
            });
            form.on('submit(searchSubmit)', function (data) {
                console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
                console.log(data.field.statDate);
                var statDate=$("#statDate").val();
                if(layid==11){
                    table.reload('userTable', {
                            url:'cashInventSelect',
                            where: {
                                date:statDate,
                            },
                            page: {
                                curr: 1
                            }
                        }
                    );
                }else if (layid==22){
                    table.reload('userTable2', {
                            url:'bondSecurity',
                            where: {
                                date:$("#statDate").val(),
                            }
                            , page: {
                                curr: 1
                            }
                        }
                    );
                }else{
                    table.reload('userTable3', {
                            url:'fundTwoFees',
                            where: {
                                date:$("#statDate").val(),
                            }
                            , page: {
                                curr: 1
                            }
                        }
                    );
                }


                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

            });

            table.on('toolbar(userTable)', function(obj){
                var data = obj.data;
                if(obj.event==='tongJi'){
                    layer.msg('开始统计');
                }
            });

            form.on('submit(tongJi)', function (data) {
                //console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
                //console.log(data.field.statDate);

                if(layid==11){
                    var checkStatus = table.checkStatus("userTable"); // 获得选中行所有数据
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var cashs = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        cashs.push(n);
                    });
                    // alert(cashs);
                    var cash = JSON.stringify(cashs);


                    layer.close();
                    //向服务端发送删除指令
                    $.post("CountingCash", "cash="+cash,function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }else if(layid==22){
                    var checkStatus = table.checkStatus("userTable2"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var Securitie = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        Securitie.push(n);
                    });
                    // alert(cashs);
                    var Securities = JSON.stringify(Securitie);
                    //var accountId=$("#accountId").val();

                    // layer.close();
                    //向服务端发送删除指令
                    $.post("BondSecuritiesMo", {Securities:Securities },function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }else{
                    var checkStatus = table.checkStatus("userTable3"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var TwoFee = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        TwoFee.push(n);
                    });
                    // alert(cashs);
                    var TwoFees = JSON.stringify(TwoFee);


                    // layer.close();
                    //向服务端发送删除指令
                    $.post("funFeesTwo", "FundTwoFees="+TwoFees,function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }

            });
        });

    </script>
</head>
<body>
<div style="margin-top: 20px;margin-left: 10px">
    <form id="searchDate" class="layui-form layui-col-space5">
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label" style="width: 110px;text-align: center">业务日期</label>

            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" autocomplete="off" placeholder="请输入统计日期" name="statDate" id="statDate">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="searchSubmit" ><i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn" type="button" lay-submit="" lay-event="tongJi" lay-filter="tongJi"><i class="layui-icon layui-icon-table"></i>统计
            </button>
        </div>
    </form>
</div>

<div class="layuimini-main">
    <div class="layui-tab layui-tab-brief" lay-filter="test1" >
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="11">现金利息</li>
            <li lay-id="22">债券利息</li>
            <li lay-id="33">两费</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <!--表格-->
                <table id="userTable" lay-filter="userTable"></table>
            </div>
            <div class="layui-tab-item">
                <table id="userTable2" lay-filter="userTable2"></table>
            </div>
            <div class="layui-tab-item">
                <table id="userTable3" lay-filter="userTable3"></table>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('element', function(){
        var element = layui.element;


        //监听Tab切换，以改变地址hash值
        element.on('tab(test1)', function(){
            location.hash = 'test1='+ this.getAttribute('lay-id');

        });
        element.on('tab(test1)', function () {
            layid = this.getAttribute('lay-id');


        });
    });
</script>
</body>
</html>